import request from 'utils/request'

/**
 * 获取文章列表
 * @param {*} params
 * @returns
 */
export const getArticles = (params) => {
  return request({
    url: '/mp/articles',
    method: 'GET',
    params,
  })
}

/**
 * 删除文章
 * @param {*} id
 * @returns
 */
export const delArticles = (id) => {
  return request({
    url: `/mp/articles/${id}`,
    method: 'DELETE',
  })
}

/**
 * 添加文章
 * @param {*} data 请求体，文章的主体内容
 * @param {*} draft 是否草稿，默认值false
 * @returns
 */
export const addArticles = (data, draft = false) => {
  return request({
    url: '/mp/articles',
    method: 'POST',
    params: {
      draft,
    },
    data,
  })
}

/**
 * 根据 id 获取文章详情
 * @param {*} id
 * @returns
 */
export const getArticlesById = (id) => {
  return request({
    url: `/mp/articles/${id}`,
    method: 'GET',
  })
}

/**
 * 根据 id 修改文章详情
 * @param {*} id
 * @param {*} data
 * @param {*} draft
 * @returns
 */
export const editArticlesById = (id, data, draft = false) => {
  return request({
    url: `/mp/articles/${id}`,
    method: 'PUT',
    params: {
      draft,
    },
    data,
  })
}
